package org.dromara.hotel.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.hotel.domain.bo.TerHotelsBo;
import org.dromara.hotel.domain.vo.TerHotelsVo;
import org.dromara.hotel.service.ITerHotelsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 酒店信息维护
 * 前端访问路由地址为:/hotel/hotels
 *
 * @author xch
 * @date 2025-05-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hotels")
public class TerHotelsController extends BaseController {

    private final ITerHotelsService terHotelsService;

    /**
     * 查询酒店信息维护列表
     */
    @SaCheckPermission("hotel:hotels:list")
    @GetMapping("/list")
    public TableDataInfo<TerHotelsVo> list(TerHotelsBo bo, PageQuery pageQuery) {
        return terHotelsService.queryPageList(bo, pageQuery);
    }
    @GetMapping("/wechat/query")
    public TableDataInfo<TerHotelsVo> query(TerHotelsBo bo, PageQuery pageQuery) {
        return terHotelsService.queryHotelByAccess(bo, pageQuery);
    }
    @GetMapping("/wechat/queryList")
    public R<List<TerHotelsVo>> queryList(TerHotelsBo bo) {
        return R.ok(terHotelsService.queryList(bo));
    }
    @GetMapping("/selectComb")
    public R<List<TerHotelsVo>> query(TerHotelsBo bo) {
        return R.ok(terHotelsService.queryList(bo));
    }
    /**
     * 导出酒店信息维护列表
     */
    @SaCheckPermission("hotel:hotels:export")
    @Log(title = "酒店信息维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerHotelsBo bo, HttpServletResponse response) {
        List<TerHotelsVo> list = terHotelsService.queryList(bo);
        ExcelUtil.exportExcel(list, "酒店信息维护", TerHotelsVo.class, response);
    }

    /**
     * 获取酒店信息维护详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("hotel:hotels:query")
    @GetMapping("/{id}")
    public R<TerHotelsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(terHotelsService.queryById(id));
    }

    /**
     * 新增酒店信息维护
     */
    @SaCheckPermission("hotel:hotels:add")
    @Log(title = "酒店信息维护", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerHotelsBo bo) {
        return toAjax(terHotelsService.insertByBo(bo));
    }

    /**
     * 修改酒店信息维护
     */
    @SaCheckPermission("hotel:hotels:edit")
    @Log(title = "酒店信息维护", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerHotelsBo bo) {
        return toAjax(terHotelsService.updateByBo(bo));
    }

    /**
     * 删除酒店信息维护
     *
     * @param ids 主键串
     */
    @SaCheckPermission("hotel:hotels:remove")
    @Log(title = "酒店信息维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(terHotelsService.deleteWithValidByIds(List.of(ids), true));
    }
}
